package com.ghf.dp9.demo;

import javax.swing.*;
import java.awt.*;

/**
 * 指挥者（Director），用它来控制建造过程，也用它来隔离用户与建造过程的关联。
 */
public class PersonDirector {
    private PersonBuilder mPersonBuilder;

    public PersonDirector(PersonBuilder personBuilder){
        mPersonBuilder = personBuilder;
    }

    public void ConstructPerson(){


        JFrame frame = new JFrame("Draw Line Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        DrawLineExample example = new DrawLineExample(mPersonBuilder);
        frame.add(example);
        frame.setSize(300, 300);
        frame.setVisible(true);

    }

    public class DrawLineExample extends JPanel {
        private PersonBuilder mPersonBuilder;
        public DrawLineExample(PersonBuilder mPersonBuilder){
            this.mPersonBuilder = mPersonBuilder;
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g); // 调用超类方法，以确保面板正确绘制


            // 设置线条的颜色（例如，黑色）
            g.setColor(java.awt.Color.BLACK);

            mPersonBuilder.setG(g);
            mPersonBuilder.BuildHead();
            mPersonBuilder.BuildBody();
            mPersonBuilder.BuildArmLeft();
            mPersonBuilder.BuildArmRight();
            mPersonBuilder.BuildLegLeft();
            mPersonBuilder.BuildLegRight();
        }
    }
}
